package com.qfedu.dao;

import com.qfedu.entity.Course;
import com.qfedu.entity.Grade;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface GradeDao {

    @Select("select * from qfoffice2.t_grade g left join qfoffice2.t_course c on c.id=g.u_no")
    List<Grade> getAllGrade();

    @Select("select name from qfoffice2.t_grade")
    List<String> getAllGradeName();

    @Delete("delete from qfoffice2.t_grade where id = #{id}")
    int deleteGradeById(int id);

    @Update("update qfoffice2.t_grade set name = #{name}, createtime = #{createtime}, week = #{week}, location = #{location} where id = #{id}")
    int updateGrade(Grade course);

    @Insert("insert into qfoffice2.t_grade (u_no, name, createtime, week, location) VALUES (#{u_no}, #{name}, #{createtime}, #{week}, #{location})")
    int insertGrade(Grade grade);

    @Select("select count(1) num, g.name from qfoffice2.t_student s left join qfoffice2.t_grade g on s.gno = g.id group by g.name")
    List<Map> getCountByGrade();

}
